package h0827;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
  * @description 子集
  * @author 不知名帅哥
  * @date 2024/8/27 21:02
  * @version 1.0
*/
public class SonCollections {
    public static void main(String[] args) {
        int[] nums={1,2,3};
        List<List<Integer>> res=getRes(nums);
        System.out.println(res);
    }

    private static List<List<Integer>> getRes(int[] nums) {
        List<List<Integer>> ans=new ArrayList<>();
        backTrack(nums,ans,new LinkedList<>(),0);
        return ans;
    }

    private static void backTrack(int[] nums, List<List<Integer>> ans, LinkedList<Integer> temp,int start) {
        ans.add(new LinkedList<>(temp));
        for (int i = start; i < nums.length; i++) {
            temp.addLast(nums[i]);
            backTrack(nums, ans, temp,i+1);
            temp.removeLast();
        }
    }
}
